﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using HF.WorkFlow.Engine;
using HF.WorkFlow.Template;
using HF.WCF.WFInterface;
using HF.WorkFlow.DataContract;
using HF.Framework.Log;
namespace HF.WCF.WFService
{
    public class WorkFlowService : IWorkFlowService
    {
        public string Start(string userId, string workFlowId, string workTaskId,
                            string commandName, string workFlowNo, string workFlowInsCaption, bool isDraft)
        {
            WorkFlowRuntime wfruntime = new WorkFlowRuntime();
            wfruntime.UserId = userId;//当前操作人id
            wfruntime.WorkFlowInstanceId = Guid.NewGuid().ToString();
            wfruntime.WorkTaskInstanceId = Guid.NewGuid().ToString();
            wfruntime.WorkFlowId = workFlowId;
            wfruntime.WorkTaskId = workTaskId;
            wfruntime.WorkFlowNo = workFlowNo;
            wfruntime.CommandName = commandName;//命令分支，必须与建模中的命令定义名相同，否则无法流转
            wfruntime.WorkflowInsCaption = workFlowInsCaption;
            wfruntime.IsDraft = isDraft;//true 表示保存草稿,执行start方法的时候流程不流转
            return wfruntime.Start();//启动流程  
        }

        public string Run(string userId, string operatorInsId, string commandName)
        {
            WorkFlowRuntime wfruntime = new WorkFlowRuntime();
            return wfruntime.Run(userId, operatorInsId, commandName);//命令分支，必须与建模中的命令定义名相同，否则无法流转
        }

       
        public string SetSuspend(string workflowInsId)//流程挂起
        {
            return WorkFlowInstance.SetSuspend(workflowInsId);
        }

        public string SetResume(string workflowInsId)//取消挂起
        {
            return WorkFlowInstance.SetResume(workflowInsId);

        }
        public string SetAbnormal(string workflowInsId, string userId, string msg)//异常终止
        {
            return WorkFlowInstance.SetAbnormal(workflowInsId, userId, msg);
        }
        public List<WorkTaskViewEntity> GetAllowsStartWorkFlowEntitys(string userId)
        {
          return  WorkFlowTemplate.GetInstance().GetAllowsStartWorkFlowEntitys(userId);
        }

        public string GetToDoWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetToDoWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetTodoWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetTodoWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetClaimWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetClaimWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetClaimWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetClaimWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetAllWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAllWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetAllWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAllWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetClaimedWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetClaimedWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetClaimedWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetClaimedWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetRunningInstanceJson(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetRunningInstanceJson(pageIndex, pageSize);
        }

        public List<WorkFlowInstanceEntity> GetRunningInstanceEntity(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetRunningInstanceEntity(pageIndex, pageSize);
        }

        public string GetCompletedInstanceJson(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetCompletedInstanceJson(pageIndex, pageSize);
        }

        public List<WorkFlowInstanceEntity> GetCompletedInstanceEntity(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetCompletedInstanceEntity(pageIndex, pageSize);
        }

        public string GetCompletedWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetCompletedWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetCompletedWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetCompletedWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetAbnormalInstanceJson(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAbnormalInstanceJson(pageIndex, pageSize);
        }

        public List<WorkFlowInstanceEntity> GetAbnormalInstanceEntity(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAbnormalInstanceEntity(pageIndex, pageSize);
        }

        public string GetSuspendInstanceJson(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetSuspendInstanceJson(pageIndex, pageSize);
        }

        public List<WorkFlowInstanceEntity> GetSuspendInstanceEntity(int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetSuspendInstanceEntity(pageIndex, pageSize);
        }

        public string GetAbnormalWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAbnormalWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetAbnormalWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetAbnormalWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public string GetSuspendWorkTaskJson(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetSuspendWorkTaskJson(userId, pageIndex, pageSize);
        }

        public List<WorkTaskInstanceViewEntity> GetSuspendWorkTaskEntity(string userId, int pageIndex, int pageSize)
        {
            return WorkFlowInstance.GetInstance().GetSuspendWorkTaskEntity(userId, pageIndex, pageSize);
        }

        public int GetClaimTaskCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetClaimTaskCount(userId);
        }

        public int GetToDoTasksCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetToDoTasksCount(userId);
        }

        public int GetClaimedTaskCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetClaimTaskCount(userId);
        }

        public int GetAllTaskCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetAllTaskCount(userId);
        }

        public int GetCompletedTaskCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetCompletedTaskCount(userId);
        }

        public int GetAbnormalTaskCount(string userId)
        {
            return WorkFlowInstance.GetInstance().GetAbnormalTaskCount(userId);
        }

        public string GetWorkFlowNO()
        {
            return WorkFlowInstance.GetWorkFlowNO();
        }

        public string GetDBDateTime()
        {
            return WorkFlowInstance.GetDBDateTime();
        }


        public List<LogEntity> GetLogEntitys(DateTime startTime,DateTime endTime)
        {
          return  LogData.GetInstance().GetLogEntitys(startTime,endTime);
            
        }
    }
}
